import { httpService } from "../service/http-service.ts";
import { netService } from "../service/net-service.ts";
import { udpService } from "../service/udp-service.ts";
import { Controller, FirewallProfileType, RouteConf } from "../type/interfaces.ts";
import {handle} from "../vendor/handle.ts";
import { electronLogger } from "../vendor/electron-logger.ts";


export default class NetController implements Controller {

  @handle("showRouteTable")
  showRouteTable() {
    return netService.showRouteTable()
  }

  @handle("deleteRoute")
  deleteRoute(e:unknown, data: RouteConf) {
    console.log(data)
    return netService.deleteRoute(data)
  }

  @handle("changeRoute")
  changeRoute(e:unknown, type: string, data: RouteConf) {
    return netService.changeRoute(type, data)
  }

  @handle("getNetworkInterfaces")
  getNetworkInterfaces() {
    return netService.getNetIfs()
  }

  @handle("getFirewallStatus")
  getFirewallStatus() {
    return netService.getFirewallStatus()
  }

  @handle("setFirewallStatus")
  setFirewallStatus(e:unknown, status: boolean, profile?: FirewallProfileType) {
    return netService.setFirewallStatus(status, profile)
  }

  @handle("restartNetworkAdapter")
  restartNetworkAdapter(_e:unknown, name: string) {
    return netService.restartNetworkAdapter(name)
  }

  @handle("setNetworkAdapterStatus")
  setNetworkAdapterStatus(_e:unknown, name: string, enable: boolean) {
    return netService.setNetworkAdapterStatus(name, enable)
  }

  @handle("startHttpService")
  startHttpService(_e:unknown, port: number) {
    return httpService.startServer(port)
  }

  @handle("stopHttpService")
  stopHttpService() {
    return httpService.stopServer()
  }

  @handle("startBroadCast")
  startBroadCast(_e:unknown, id: string, port: number) {
    electronLogger.info(`Starting Broad Cast`, id, port)
    return udpService.startBroadCast(id, port)
  }

  @handle("stopBroadCast")
  stopBroadCast() {
    return udpService.stopBroadCast()
  }

  @handle("beginClient")
  beginClient(_e:unknown, port: number) {
    return udpService.beginClient(port)
  }


  @handle("stopClient")
  stopClient() {
    return udpService.stopClient()
  }
}
export const netController = new NetController()
